'use strict';
exports = module.exports = function ($scope, $rootScope, $timeout, $alert, $state, $uibModal, yxtable14, $compile, $rule, throttleSubmit) {
    var $API = {};
    $API.Detail = {};
    $API.Drop = {};
    var $ajax = {};
    $ajax.sent = function(param) {
        return new Promise(function(resolve, reject) {
            if(param.url == 'cardfromDetail') {
                var mock = {
                    "code": 200,
                    "msg":"",
                    "data": {
                    }
                };
                var Random = Mock.Random;
                mock.data = {
                    "cnzzHourCountMax": Random.natural(1, 100),
                    "floatingRate": Random.natural(1, 100),
                    "downRate": Random.natural(1, 100)
                }
                resolve(mock);
                return false;
            }
        });
    };
    $API.Detail.cardfrom = function(opt) {
        return new Promise(function(resolve, reject){
            $ajax.sent({
                method: 'GET',
                url: 'cardfromDetail',
                params: opt // 传参
            }).then(function(res){
                resolve(res.data)
            });
        });
    };
    ///////////////////////////////////////
    $scope.Rule = $rule;
    $scope.frm = {
        "cnzzHourCountMax": '',
        "floatingRate": '',
        "downRate": ''
    }
    $scope.frm2 = {
        // 数据源: 彩票类型列表
        lotteryTypeList: select2Config( [] ),
        // 数据源: 彩票类型2列表
        lotteryType2List: select2Config( [] ),

        f10add: function(){
            if(!$scope.frm.f09){
                return false
            }
            // 冗余写法目的是解决数组必填验证逻辑
            // 不可使用$scope.frm.f10.push
            var xx = angular.copy($scope.frm.f10);
            xx.push($scope.frm.f09);
            $scope.frm.f09 = ''
            $scope.frm.f10 = xx
        },
        f10delete: function(index){
            // 冗余写法目的是解决数组必填验证逻辑
            // 不可使用$scope.frm.f10.splice
            var xx = angular.copy($scope.frm.f10);
            xx.splice(index, 1);
            $scope.frm.f10 = xx
        },
    }
    var id = 12; // 获取到传参 比如$stateparam
    $API.Detail.cardfrom({id:id})
    .then(function(data) {
        $timeout(function() {
            angular.extend($scope.frm, data)
        }, 0)
    });
    $scope.submitFun = throttleSubmit(function(){
        $scope.From.submitted = true;
        if( $scope.From.$invalid ) {
            $alert.error('请检查提交的信息')
            return false;
        }
        return $scope.frm
    },function(enable, param){
        console.log('提交代码', param)
        $timeout(function(){
            enable()
        },3e3)
    });
    $scope.cancelFun = function(){
        $alert.confirm("是否取消编辑？", function(close){
            // $go('app.make.maketable1');
            close();
        })
    };
}